package com.shurdroides.sintesi;

import java.util.List;

import javax.persistence.EntityManager;

public class PaisHelper implements Controller<Long,Pais>{
	EntityManager em;
	
	public PaisHelper(EntityManager em){
		setEntityManager(em);
	}
	
	
	@Override
	public void makePersistent(Pais object) {

		try{
			em.getTransaction().begin();
			em.persist(object);
			em.getTransaction().commit();
		}catch(Exception e){
			em.getTransaction().rollback();
			e.printStackTrace();
		}finally{

		}
		
	}

	@Override
	public void update(Pais object) {
		try{
			em.getTransaction().begin();
			em.merge(object);
			em.getTransaction().commit();
		}catch(Exception e){
			em.getTransaction().rollback();
			e.printStackTrace();
		}finally{

		}
		
	}

	@Override
	public void remove(Pais object) {

		try{
			em.getTransaction().begin();
			em.remove(object);
			em.getTransaction().commit();
		}catch(Exception e){
			em.getTransaction().rollback();
			e.printStackTrace();
		}finally{

		}
		
	}

	@Override
	public Pais getById(Long clau) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Pais getByName(String name) {

		Pais u = (Pais) em.createQuery("select o from Pais o where o.nombre=\""+name+"\"").getSingleResult();
		return u;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void removeAll() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public List<Pais> getList() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean containsKey(Long clau) {
		// TODO Auto-generated method stub
		return false;
	}
	
	@Override
	public void setEntityManager(EntityManager em) {
		this.em=em;
		
	}

}
